package top.ranzhang.controller.admin;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.ranzhang.bean.entity.HomeworkGrades;
import top.ranzhang.common.result.Result;
import top.ranzhang.service.IHomeworkGradesService;

/**
 * 作业与成绩
 */

@RestController
@RequestMapping("/admin/homework-grades")
public class HomeworkGradesController {

    @Autowired
    private IHomeworkGradesService homeworkGradeService;
    /**
     * 创建作业成绩
     *
     * @param homeworkGrade
     */
    @PostMapping
    public Result create(@RequestBody HomeworkGrades homeworkGrade) {
        homeworkGradeService.save(homeworkGrade);
        return Result.success();
    }

    /**
     * 获取所有作业成绩
     *
     * @return
     */
    @GetMapping
    public Result getAll() {
        return Result.success(homeworkGradeService.getAll());
    }

    /**
     * 根据ID获取作业成绩
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        return Result.success(homeworkGradeService.getById(id));
    }

    /**
     * 更新作业成绩
     *
     * @param id
     * @param homeworkGrade
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable Integer id, @RequestBody HomeworkGrades homeworkGrade) {
        homeworkGrade.setHomeworkId(id);
        homeworkGradeService.update(homeworkGrade);
        return Result.success();
    }

    /**
     * 删除作业成绩
     *
     * @param id
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        homeworkGradeService.delete(id);
        return Result.success();
    }


}
